package com.woshengqile.service;

import net.hasor.core.Singleton;

import com.jfinal.kit.LogKit;
import com.woshengqile.cache.J2CacheKit;

/**
 * Service - 缓存
 * 
 */
@Singleton
public class CacheService {

	//private CacheManager cacheManager = CacheKit.getCacheManager();
	//private Configuration freeMarkerConfigurer = FreeMarkerRender.getConfiguration();
	
	/**
	 * 获取缓存存储路径
	 * 
	 * @return 缓存存储路径
	 */
	public String getDiskStorePath() {
		return null;
		//return cacheManager.getConfiguration().getDiskStoreConfiguration().getPath();
	}

	/**
	 * 获取缓存数
	 * 
	 * @return 缓存数
	 */
	public int getCacheSize() {
		int cacheSize = 0;
//		String[] cacheNames = cacheManager.getCacheNames();
//		if (cacheNames != null) {
//			for (String cacheName : cacheNames) {
//				Ehcache cache = cacheManager.getEhcache(cacheName);
//				if (cache != null) {
//					cacheSize += cache.getSize();
//				}
//			}
//		}
		return cacheSize;
	}

	/**
	 * 清除缓存
	 */
	public void clear() {
		//freeMarkerConfigurer.clearTemplateCache();
//		String[] cacheNames = new String[] { "setting", 
//				"templateConfig", "pluginConfig", "messageConfig", 
//				"index", "area", "seo", "adPosition", 
//				"memberAttribute", "businessAttribute", "navigation", 
//				"friendLink", "brand", "attribute", 
//				"article", "articleCategory", "articleTag", 
//				"product", "productCategory", "storeProductCategory", "productTag", "productFavorite",
//				"review", "consultation", "promotion", "sitemap", 
//				"commonJs", "transitSteps", "authorization",
//				"mobileIndex", "mobileProductDetail", "mobileProductCategoryRoots", "mobileProductCategoryChildrens", "mobileProducts" };
		String[] cacheNames = new String[] { "mobileIndex", "mobileProductDetail", "mobileProductCategoryRoots", "mobileProductCategoryChildrens", "mobileProducts" };
		for (String cacheName : cacheNames) {
			LogKit.info("正在清空缓存名：[ " + cacheName + "]的缓存...");
			J2CacheKit.clear(cacheName);
		}
	}

}